package com.hk.yajin.function.videos.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hk.developmentlib.utills.StringHelper;
import com.hk.developmentlib.utills.UiUtil;
import com.hk.developmentlib.utills.glide.GlideCircleTransform;
import com.hk.yajin.R;
import com.hk.yajin.model.ViewPorint;

import java.util.List;

/**
 * https://github.com/CymChad/BaseRecyclerViewAdapterHelper
 */
public class ViewPorintMultQuickAdapter extends BaseMultiItemQuickAdapter<ViewPorint, BaseViewHolder> {

    public final static int TYPE_PIC = 0;
    public final static int TYPE_TXT = 1;
    private Context context;

    public ViewPorintMultQuickAdapter(List<ViewPorint> datas, Context ct) {
        super(datas);
        context = ct;
        addItemType(0, R.layout.list_item_porint_pic);
        addItemType(1, R.layout.list_item_porint_txt);
    }

    @Override
    protected void convert(BaseViewHolder helper, ViewPorint item) {

        switch (item.getItemType()) {
            case 0:
                setTypePic(helper, item);
                break;
            default:
                setTypeTxt(helper, item);
                break;
        }

    }

    private void setTypePic(BaseViewHolder helper, ViewPorint item) {

        //教师名
        if (!TextUtils.isEmpty(item.getTe_name())) {
            helper.setText(R.id.tv_user, item.getTe_name());
        } else {
            helper.setText(R.id.tv_user, "");
        }

        //标题
        if (!TextUtils.isEmpty(item.getView_title())) {
            helper.setText(R.id.tv_title, item.getView_title());
        } else {
            helper.setText(R.id.tv_title, "");
        }
        //简介
        if (!TextUtils.isEmpty(item.getView_brief())) {
            helper.setText(R.id.tv_sum, item.getView_brief());
        } else {
            helper.setText(R.id.tv_sum, "");
        }
/*时间显示*/
        String time = StringHelper.friendlyPubTime(item.getCreate_time()*1000L);
        helper.setText(R.id.tv_time, time);
        /*游览数目*/
        helper.setText(R.id.tv_read_count, item.getView_watch_count()+"游览");
         /*点赞数目*/
        helper.setText(R.id.tv_zan_count, item.getView_like_count() + "点赞");
        /*图片*/
        ImageView imageView = helper.getView(R.id.iv_logo);
        imageView.getLayoutParams().width = UiUtil.getScreenWidth() / 3;
        float rate = 15.0f / 22.0f;
        imageView.getLayoutParams().height = (int) (UiUtil.getScreenWidth() / 3 * rate);

        /*头像*/
       // Glide.with(context).load(item.getView_cover()).placeholder(R.color.oriag2).error(R.mipmap.user_head).transform(new GlideCircleTransform(context)).into((ImageView) helper.getView(R.id.iv_user));
        UiUtil.showNormalImage(imageView, item.getView_cover());
        UiUtil.showCircleImage((ImageView) helper.getView(R.id.iv_user), item.getTe_avatar());
    }

    private void setTypeTxt(BaseViewHolder helper, ViewPorint item) {
        //教师名
        if (!TextUtils.isEmpty(item.getTe_name())) {
            helper.setText(R.id.tv_user, item.getTe_name());
        } else {
            helper.setText(R.id.tv_user, "");
        }

        //标题
        if (!TextUtils.isEmpty(item.getView_title())) {
            helper.setText(R.id.tv_title, item.getView_title());
        } else {
            helper.setText(R.id.tv_title, "");
        }
        //简介
        if (!TextUtils.isEmpty(item.getView_brief())) {
            helper.setText(R.id.tv_sum, item.getView_brief());
        } else {
            helper.setText(R.id.tv_sum, "");
        }
/*时间显示*/
        String time = StringHelper.friendlyPubTime(item.getCreate_time()*1000L);
        helper.setText(R.id.tv_time, time);
        /*游览数目*/
        helper.setText(R.id.tv_read_count, item.getView_watch_count());
         /*点赞数目*/
        helper.setText(R.id.tv_zan_count, item.getView_like_count() + "点赞");

        /*头像*/
        Glide.with(context).load(item.getView_cover()).transform(new GlideCircleTransform(context)).into((ImageView) helper.getView(R.id.iv_user));
    }


}
